#import db
import sys
import os
import error_handler
from PyQt4 import QtGui
from PyQt4 import QtCore

PP2EpackageRoots = [                               # python module search path
   #'%sPP2E' % os.sep,                             # pass in your own elsewhere
    ''] 

class BFoundError(Exception):
   def __init__(self, value):
      datatxt =  "BFoundError: b character found at position %s" % value
      app = QtGui.QApplication(sys.argv)
      w = error_handler.ERDialog("test",datatxt)
      #w = error_handler.MessageBox("EROOR", "ERROR", datatxt)
      w.show()
      sys.exit(app.exec_())

string = "You make me want to be a better man."

def testpath():
   #data = sys.path()
   data = str(os.path.split(sys.argv[0])[0]).split("\\")
   #for i in range(0,len(data) - 1):
   #data.append(os.path.curdir)
   #print data
   datap = os.environ['PYTHONPATH']
   os.environ['PYTHONPATH'] = os.environ['PYTHONPATH'] + os.pathsep + os.getcwd()
   print os.environ['PYTHONPATH']
   
def configPythonPath(examplesDir, packageRoots=PP2EpackageRoots, trace=1):
   
   """
    Setup the Python module import search-path directory 
    list as necessary to run programs in the book examples 
    distribution, in case it hasn't been configured already.
    Add examples package root, plus nested package roots.
    This corresponds to the setup-pp* config file settings.
    os.environ assignments call os.putenv internally in 1.5,
    so these settings will be inherited by spawned programs.
    Python source lib dir and '.' are automatically searched;
    unix|win os.sep is '/' | '\\', os.pathsep is ':' | ';'.
    sys.path is for this process only--must set os.environ.
    adds new dirs to front, in case there are two installs.
    could also try to run platform's setup-pp* file in this
    process, but that's non-portable, slow, and error-prone.
    """
   try:
      ospythonpath = os.environ['PYTHONPATH']
   except:
      ospythonpath = '' # okay if not set 
   if trace: print 'PYTHONPATH start:\n', ospythonpath
   addList = []
   for root in packageRoots:
      importDir = examplesDir + root
      if importDir in sys.path:
         if trace: print 'Exists', importDir
      else:
         if trace: print 'Adding', importDir
         sys.path.append(importDir)
         addList.append(importDir)
   if addList:
      addString = string.join(addList, os.pathsep) + os.pathsep
      os.environ['PYTHONPATH'] = addString + ospythonpath
      if trace: print 'PYTHONPATH updated:\n', os.environ['PYTHONPATH']
   else:
      if trace: print 'PYTHONPATH unchanged'



#BFoundError = error_handler.ErrorFound()

if __name__ == '__main__':
   """try:
      print sys.argv[1]
      #pos = 0
      #for i in string:
      #   if i == 'b':
      #      raise BFoundError, pos
      #      #raise error_handler, pos
      #   pos = pos + 1
   
   except IndexError, e:
      raise BFoundError(e)
   """
   testpath()